import { Modal } from '@arco-design/web-vue';

export interface IWarningConfirmProps {
  title: string;
  content: string;
  onBeforeOk: () => Promise<any>;
  onSuccess?: (res: any) => void;
}

export const showWarningConfirm = (props: IWarningConfirmProps) => {
  Modal.confirm({
    title: props.title,
    content: props.content,
    simple: false,
    onBeforeOk: () => {
      return props
        .onBeforeOk()
        .then((res) => {
          if (props.onSuccess) {
            props.onSuccess(res);
          }
          return true;
        })
        .catch(() => {
          return false;
        });
    },
  });
};
